import React, { useEffect, useState } from "react";
import { useHistory } from "react-router-dom";

const Index = () => {
  const [list, setList] = useState([]);
  const history = useHistory();

  useEffect(() => {
    fetch("http://pudge.wang:3080/api/movies/list")
      .then((response) => response.json())
      .then((res) => {
        setList(res.result);
      });
  }, []);

  const goDetail = (id) => () => {
    history.push("/detail/" + id);
  };

  return (
    <>
      <div>这是热映页面</div>
      {list.map((item) => (
        <div key={item._id} onClick={goDetail(item.movieid)}>
          {item.nm}
        </div>
      ))}
    </>
  );
};

export default Index;
